package com.lwz.flyweight;

import java.util.Map;

/**
 * 享元工厂
 * @author liuwangzhen
 *
 */
public class FlyweightFactory {
	//工厂单例
	private static FlyweightFactory factory = new FlyweightFactory();
	
	private FlyweightFactory(){
		
	}
	
	public static FlyweightFactory getFlyweightFactory(){
		return factory;
	}
	
	private Map<String,Flyweight> weightMap = MapUtils.newInstance();
	
	
	public Flyweight getFlyweight(String key){
		Flyweight flyweight = weightMap.get(key);
		if(weightMap==null){
			flyweight = new AuthenticationFlyweight(key);
			weightMap.put(key, flyweight);
		}
		return flyweight;
	}

}
